from typing import List

import pytest
import yaml
from selenium import webdriver


@pytest.fixture(scope='class')
def wework_addperson():
    opt = webdriver.ChromeOptions()
    # 设置debug地址
    opt.debugger_address = "127.0.0.1:9222"
    driver = webdriver.Chrome(options=opt)
    driver.implicitly_wait(10)
    yield driver
    driver.quit()


def get_persondatas():
    with open("number.yaml") as f:
        person_datas = yaml.safe_load(f)
    return person_datas


# 姓名
@pytest.fixture(params=get_persondatas()['username'], ids=get_persondatas()['username_ids'])
def get_username(request):
    return request.param


# 别名
@pytest.fixture(params=get_persondatas()['memberAdd_english_name'], ids=get_persondatas()['memberAdd_english_name_ids'])
def get_memberAdd_english_name(request):
    return request.param


# 账号
@pytest.fixture(params=get_persondatas()['memberAdd_acctid'], ids=get_persondatas()['memberAdd_acctid_ids'])
def get_memberAdd_acctid(request):
    return request.param


# 性别
@pytest.fixture(params=get_persondatas()['gender'], ids=get_persondatas()['gender_ids'])
def get_gender(request):
    return request.param


# 手机
@pytest.fixture(params=get_persondatas()['memberAdd_phone'], ids=get_persondatas()['memberAdd_phone_ids'])
def get_memberAdd_phone(request):
    return request.param


# 座机
@pytest.fixture(params=get_persondatas()['memberAdd_telephone'], ids=get_persondatas()['memberAdd_telephone_ids'])
def get_memberAdd_telephone(request):
    return request.param


# 邮箱
@pytest.fixture(params=get_persondatas()['memberAdd_mail'], ids=get_persondatas()['memberAdd_mail_ids'])
def get_memberAdd_mail(request):
    return request.param


# 地址
@pytest.fixture(params=get_persondatas()['memberEdit_address'], ids=get_persondatas()['memberEdit_address_ids'])
def get_memberEdit_address(request):
    return request.param


# 部门
@pytest.fixture(params=get_persondatas()['bumnen'], ids=get_persondatas()['bumnen_ids'])
def get_bumnen(request):
    return request.param


# 职务
@pytest.fixture(params=get_persondatas()['memberAdd_title'], ids=get_persondatas()['memberAdd_title_ids'])
def get_memberAdd_title(request):
    return request.param


# 身份
@pytest.fixture(params=get_persondatas()['identity_stat'], ids=get_persondatas()['identity_stat_ids'])
def get_identity_stat(request):
    return request.param


# 职务选择
@pytest.fixture(params=get_persondatas()['position'], ids=get_persondatas()['position_ids'])
def get_position(request):
    return request.param


# 职务为自定义时自定义输入框内容
@pytest.fixture(params=get_persondatas()['zidingyishuru'], ids=get_persondatas()['zidingyishuru_ids'])
def get_zidingyishuru(request):
    return request.param


# 是否发送邀请
@pytest.fixture(params=get_persondatas()['sendmessage'], ids=get_persondatas()['sendmessage_ids'])
def get_sendmessage(request):
    return request.param


def pytest_collection_modifyitems(session, config, items: List):
    print("这是收集所有测试用例的方法")
    print(items)
    for item in items:
        # 拿到测试用例的名字，对它进行重编码，编码成utf-8的格式（utf-8是支持所有格式的）
        item.name = item.name.encode('utf-8').decode('unicode-escape')
        item._nodeid = item.nodeid.encode('utf-8').decode('unicode-escape')
